<template>
  <div class="dashboard-editor-container">

    <panel-group @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="lineChartData" />
    </el-row>
  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'

export default {
  name: 'DashboardAdmin',
  components: {
    PanelGroup,
    LineChart
  },
  data() {
    return {
      lineChartData: {}
    }
  },
  created() {
  },
  methods: {
    handleSetLineChartData(title, type, bizType) {
      this.lineChartData = {
        totalAmountDatas: [],
        totalNumDatas: [],
        xAxisDatas: []
      }
      if (type === 'today') {
        this.$api.chart.orderChart.queryToday({
          bizType: bizType
        }).then(res => {
          this.lineChartData = {
            totalAmountDatas: res.map(item => item.totalAmount),
            totalNumDatas: res.map(item => item.totalNum),
            xAxisDatas: res.map(item => item.createHour.substring(item.createHour.length - 2) + '时'),
            title: title
          }
        })
      } else {
        this.$api.chart.orderChart.querySameMonth({
          bizType: bizType
        }).then(res => {
          this.lineChartData = {
            totalAmountDatas: res.map(item => item.totalAmount),
            totalNumDatas: res.map(item => item.totalNum),
            xAxisDatas: res.map(item => item.createDate),
            title: title
          }
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
